import child_process from 'child_process';

const commitId = child_process.execSync('git show -s --format=%H').toString().trim();
const commitUserName = child_process.execSync('git show -s --format=%cn').toString().trim();
const commitUserMail = child_process.execSync('git show -s --format=%ce').toString().trim();
const commitDateObj = new Date(child_process.execSync(`git show -s --format=%cd`).toString());
const commitDate = `${commitDateObj.getFullYear() + '-' + (commitDateObj.getMonth() + 1) + '-' + commitDateObj.getDate() + ' ' + commitDateObj.getHours() + ':' + commitDateObj.getMinutes() + ':' + commitDateObj.getSeconds()}`;

const buildUserName = child_process.execSync('git config user.name').toString().trim();
const buildUserMail = child_process.execSync('git config user.email').toString().trim();
const buildDateObj = new Date();
const buildDate = `${buildDateObj.getFullYear() + '-' + (buildDateObj.getMonth() + 1) + '-' + buildDateObj.getDate() + ' ' + buildDateObj.getHours() + ':' + buildDateObj.getMinutes() + ':' + buildDateObj.getSeconds()}`;

const message = child_process.execSync('git show -s --format=%s').toString().trim();

process.env.VITE_GIT_COMMIT_ID = commitId;
process.env.VITE_GIT_COMMIT_USER_NAME = commitUserName;
process.env.VITE_GIT_COMMIT_USER_MAIL = commitUserMail;
process.env.VITE_GIT_COMMIT_DATE = commitDate;
process.env.VITE_GIT_BUILD_USER_NAME = buildUserName;
process.env.VITE_GIT_BUILD_USER_MAIL = buildUserMail;
process.env.VITE_GIT_BUILD_DATE = buildDate;
process.env.VITE_GIT_MESSAGE = message;
